<template>
	<view>
		<view style="padding: 10px;display: flex;gap: 10px;">
			<uni-section title="首页banner" sub-title="商城页滚动头图" type="square">
				<template v-slot:right>
					<uni-icons :type="showSection===0?'down':'right'" @click="showSection=0" color="#007aff"
						size="30"></uni-icons>
				</template>
				<view v-if="showSection === 0" class="table-container" style="max-height: 60vh;">
					<uni-table emptyText="暂无更多数据">
						<uni-tr class="table-head">
							<uni-th align="center" width="30">ID</uni-th>
							<uni-th>封面</uni-th>
							<uni-th>名称</uni-th>
							<uni-th>类型</uni-th>
							<uni-th>排序</uni-th>
							<uni-th>状态</uni-th>
							<uni-th>链接</uni-th>
							<uni-th>描述</uni-th>
							<uni-th></uni-th>
							<uni-th>
								<view style="display: flex;gap: 5px;"><text class="gl-link gl-link-success">新增</text>
									<text class="gl-link gl-link-base" @click="loadBanner">刷新</text>
								</view>
							</uni-th>
						</uni-tr>
						<uni-tr v-for="(banner, idx) in bannerArray" :key="'banner'+idx">
							<uni-td align="center" width="30">{{banner.id}}</uni-td>
							<uni-td>
								<image :src="sConf.cos + (banner.media ?? '/media/default/cover.png')"
									mode="scaleToFill" style="width: 128px;height: 72px;border-radius: 5px;"></image>
							</uni-td>
							<uni-td>{{banner.title}}</uni-td>
							<uni-td>{{banner.type}}</uni-td>
							<uni-td>{{banner.hot}}</uni-td>
							<uni-td>
								<switch :checked="banner.status === 1" :disabled="true" style="transform:scale(0.5)"
									@change="event => EventStateChange(event, banner.id)" />
							</uni-td>
							<uni-td>{{banner.urls}}</uni-td>
							<uni-td>{{banner.desc ?? '...'}}</uni-td>
							<uni-td>
								<view style="display: flex;gap: 5px;">
									<text class="gl-link gl-link-base">编辑</text>
									<text class="gl-link gl-link-error">移除</text>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>
			</uni-section>

			<uni-section title="首页矩阵" sub-title="商城页矩阵配置" type="square">
				<template v-slot:right>
					<uni-icons :type="showSection===1?'down':'right'" @click="showSection=1" color="#007aff"
						size="30"></uni-icons>
				</template>
				<view v-if="showSection===1" class="table-container" style="max-height: 60vh;">
					<uni-table emptyText="暂无更多数据">
						<uni-tr class="table-head">
							<uni-th align="center">ID</uni-th>
							<uni-th>封面</uni-th>
							<uni-th>模块</uni-th>
							<uni-th>状态</uni-th>
							<uni-th>链接</uni-th>
							<uni-th></uni-th>
							<uni-th>
								<view style="display: flex;gap: 5px;"><text class="gl-link gl-link-base"
										@click="loadGrid">刷新</text>
								</view>
							</uni-th>
						</uni-tr>
						<uni-tr v-for="(banner, idx) in gridArray" :key="'banner'+idx">
							<uni-td align="center">{{banner.id}}</uni-td>
							<uni-td>
								<image :src="sConf.cos + (banner.icon ?? '/media/default/cover.png')" mode="scaleToFill"
									style="width: 128px;height: 72px;border-radius: 5px;"></image>
							</uni-td>
							<uni-td>{{banner.title}}</uni-td>
							<uni-td>
								<switch :checked="banner.show === 1" style="transform:scale(0.5)" :disabled="true"
									@change="event => EventStateChange(event, banner.id)" />
							</uni-td>
							<uni-td>{{banner.url}}</uni-td>
							<uni-td>
								<view style="display: flex;gap: 5px;">
									<text class="gl-link gl-link-base">编辑</text>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>
			</uni-section>

			<uni-section title="个人中心" sub-title="个人页网格矩阵配置" type="square">
				<template v-slot:right>
					<uni-icons :type="showSection===2?'down':'right'" @click="showSection=2" color="#007aff"
						size="30"></uni-icons>
				</template>
				<view v-if="showSection===2" class="table-container" style="max-height: 60vh;">
					<uni-table emptyText="暂无更多数据">
						<uni-tr class="table-head">
							<uni-th align="center">ID</uni-th>
							<uni-th>图标</uni-th>
							<uni-th>模块</uni-th>
							<uni-th>状态</uni-th>
							<uni-th>链接</uni-th>
							<uni-th></uni-th>
							<uni-th>
								<view style="display: flex;gap: 5px;">
									<text class="gl-link gl-link-success">新增</text>
									<text class="gl-link gl-link-base" @click="loadMyGrid">刷新</text>
								</view>
							</uni-th>
						</uni-tr>
						<uni-tr v-for="(banner, idx) in myGridArray" :key="'banner'+idx">
							<uni-td align="center" width="30">{{idx + 1}}</uni-td>
							<uni-td>
								<view style="display: flex;gap: 5px;">
									<uni-icons :type="banner.icon ?? 'spinner-cycle'" size="30"></uni-icons>
									<text>{{banner.icon}}</text>
								</view>
							</uni-td>
							<uni-td>{{banner.title}}</uni-td>
							<uni-td>
								<switch :checked="banner.show === 1" style="transform:scale(0.5)" :disabled="true"
									@change="event => EventStateChange(event, banner.id)" />
							</uni-td>
							<uni-td>{{banner.url ?? '/pageb/empty/empty'}}</uni-td>
							<uni-td>
								<view style="display: flex;gap: 5px;">
									<text class="gl-link gl-link-base">编辑</text>
									<text class="gl-link gl-link-error">移除</text>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>
			</uni-section>
		</view>

		<view>
			<uni-section title="其他设置" sub-title="全局综合设置" type="square">
				<template v-slot:right>
					<uni-icons :type="showSection===3?'down':'right'" @click="showSection=3" color="#007aff"
						size="30"></uni-icons>
				</template>
				<view v-if="showSection===3" style="display: flex;flex-wrap: wrap;gap: 10px;">
					<uni-card title="项目名称" sub-title="个人中心权益页面地址">
						<uni-easyinput v-model="appTitle" prefixIcon="home" placeholder="个人中心权益页面地址" :trim="true"
							:disabled="showTitle" />
						<view slot="actions" style="display: flex;justify-content: space-around;padding-top: 10px;">
							<text class="gl-button gl-button-base" @click="showTitle=!showTitle">编辑</text>
							<text class="gl-button gl-button-success" @click="loadMyTitle">刷新</text>
						</view>
					</uni-card>

					<uni-card title="个人页二维码" sub-title="扫码后跳转的目标地址">
						<uni-easyinput v-model="scanTarget" prefixIcon="scan" placeholder="扫码后跳转的目标地址" :trim="true"
							:disabled="showScan" />
						<view slot="actions" style="display: flex;justify-content: space-around;padding-top: 10px;">
							<text class="gl-button gl-button-base" @click="showScan=!showScan">编辑</text>
							<text class="gl-button gl-button-success" @click="loadMyQrcode">刷新</text>
						</view>
					</uni-card>

					<uni-card title="个人页权益" sub-title="个人中心权益页面地址">
						<uni-easyinput v-model="levelList" prefixIcon="paperplane" placeholder="个人中心权益页面地址" :trim="true"
							:disabled="showLevel" />
						<view slot="actions" style="display: flex;justify-content: space-around;padding-top: 10px;">
							<text class="gl-button gl-button-base" @click="showLevel=!showLevel">编辑</text>
							<text class="gl-button gl-button-success" @click="loadMyLevel">刷新</text>
						</view>
					</uni-card>

					<uni-card title="签到设置" sub-title="每日签到积分奖励">
						<view style="display: flex;flex-direction: column;gap: 5px;">
							<view style="display: flex;gap: 10px;align-items: center;">
								<text>奖励基数</text>
								<uni-easyinput :value="fliterDaily('daily_day')" type="number" placeholder="积分奖励基数"
									:trim="true" :disabled="showDaily" />
							</view>
							<view style="display: flex;gap: 10px;align-items: center;">
								<text>递增基数</text>
								<uni-easyinput :value="fliterDaily('daily_radix')" type="number" placeholder="积分递增基数"
									:trim="true" :disabled="showDaily" />
							</view>
							<view style="display: flex;gap: 10px;align-items: center;">
								<text>最大连击</text>
								<uni-easyinput :value="fliterDaily('daily_radix_max')" type="number"
									placeholder="最大连击(天)" :trim="true" :disabled="showDaily" />
							</view>
						</view>
						<view slot="actions" style="display: flex;justify-content: space-around;padding-top: 10px;">
							<text class="gl-button gl-button-base" @click="showDaily=!showDaily">编辑</text>
							<text class="gl-button gl-button-success" @click="loadSetPoint">刷新</text>
						</view>
					</uni-card>

					<uni-card title="提现设置" sub-title="最小提现金额(元)">
						<uni-easyinput v-model="minMoney" prefixIcon="wallet" type="digit" placeholder="最小提现金额"
							:trim="true" :disabled="showDraw" />
						<view slot="actions" style="display: flex;justify-content: space-around;padding-top: 10px;">
							<text class="gl-button gl-button-base" @click="showDraw=!showDraw">编辑</text>
							<text class="gl-button gl-button-success" @click="loadMinMoney">刷新</text>
						</view>
					</uni-card>
				</view>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import psMethod from '@/common/psMethod';
	export default {
		data() {
			return {
				title: '页面设置',
				sConf: getApp().globalData,
				showSection: 0,
				bannerArray: [],
				gridArray: [],
				myGridArray: [],
				appTitle: null,
				showTitle: true,
				scanTarget: null,
				showScan: true,
				levelList: null,
				showLevel: true,
				setDaily: [],
				showDaily: true,
				minMoney: null,
				showDraw: true
			}
		},
		mounted() {
			this.loadDefData()
		},
		methods: {
			EventStateChange(e, idx) {
				console.log('change', e, idx);
			},
			async loadDefData() {
				await this.loadMinMoney()
				await this.loadSetPoint()
				await this.loadMyTitle()
				await this.loadMyLevel()
				await this.loadMyQrcode()
				await this.loadMyGrid()
				await this.loadGrid()
				await this.loadBanner()
			},
			loadMinMoney() {
				psMethod.syncAnonymousRequest('/api/conf/', 'GET', {
					key: 'wallet_min_money'
				}).then(res => {
					console.log('加载', res);
					this.minMoney = (res.resmsg[0].value / 100).toFixed(2) ?? 0
					this.showDraw = true
				})
			},
			fliterDaily(e) {
				return this.setDaily.find(item => item.key === e).value ?? 0
			},
			loadSetPoint() {
				psMethod.syncAnonymousRequest('/api/conf/', 'GET', {
					search: 'daily_'
				}).then(res => {
					console.log('加载', res);
					this.setDaily = res.resmsg
					this.showDaily = true
				})
			},
			loadMyTitle() {
				psMethod.syncAnonymousRequest('/api/conf/', 'GET', {
					key: 'system_title'
				}).then(res => {
					console.log('加载', res);
					this.appTitle = res.resmsg[0].value
					this.showTitle = true
				})
			},
			loadMyLevel() {
				psMethod.syncAnonymousRequest('/m2/conf/', 'GET', {
					idx: 41,
					ordering: '-hot'
				}).then(res => {
					console.log('加载', res);
					this.levelList = res.resmsg[0].value
					this.showLevel = true
				})
			},
			loadMyQrcode() {
				psMethod.syncAnonymousRequest('/m2/conf/', 'GET', {
					idx: 42,
					ordering: '-hot'
				}).then(res => {
					console.log('加载', res);
					this.scanTarget = res.resmsg[0].value
					this.showScan = true
				})
			},
			loadMyGrid() {
				psMethod.syncAnonymousRequest('/m2/conf/', 'GET', {
					idx: 40,
					ordering: '-hot'
				}).then(res => {
					let tmpData = JSON.parse(res.resmsg[0].value)
					this.myGridArray = tmpData
					console.log('加载myGrid', tmpData);
				})
			},
			loadGrid() {
				psMethod.syncAnonymousRequest('/m2/conf/', 'GET', {
					idx: 10,
					ordering: '-hot'
				}).then(res => {
					let tmpData = JSON.parse(res.resmsg[0].value)
					this.gridArray = tmpData
					console.log('加载grid', tmpData);
				})
			},
			loadBanner() {
				psMethod.syncAnonymousRequest('/m2/banner/', 'GET', {
					ordering: '-hot'
				}).then(res => {
					console.log('加载banner', res);
					this.bannerArray = res.resmsg
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>